/**
 * Created by tangsong on 3/17/17.
 */

function getArgs() {
  var args = {};
  var query = location.search.substring(1);
  // Get query string
  var pairs = query.split("&");
  // Break at ampersand
  for (var i = 0; i < pairs.length; i++) {
    var pos = pairs[i].indexOf('=');
    // Look for "name=value"
    if (pos == -1) continue;
    // If not found, skip
    var argname = pairs[i].substring(0, pos);// Extract the name
    var value = pairs[i].substring(pos + 1);// Extract the value
    value = decodeURIComponent(value);// Decode it, if needed
    args[argname] = value;
    // Store as a property
  }
  return args;// Return the object
}

$(function () {

  var clipboard = new Clipboard(".clone-btn");
  clipboard.on('success', function (e) {
    showTooltip(e.trigger, '复制成功!');
  });

  clipboard.on('error', function (e) {
    console.log(e);
    alert("复制失败");
  });
  var args = getArgs();

  var splits = window.location.href;
  console.log(splits);
  $("#clone_url").val(splits);


  var btns = document.querySelectorAll('.clone-btn');
  for (var i = 0; i < btns.length; i++) {
    btns[i].addEventListener('mouseleave', function (e) {
      e.currentTarget.setAttribute('class', 'clone-btn');
      e.currentTarget.removeAttribute('aria-label');
    });
  }
  function showTooltip(elem, msg) {
    elem.setAttribute('class', 'clone-btn tooltipped tooltipped-s');
    elem.setAttribute('aria-label', msg);
  }
});


